home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: DoEvent.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.defs.h" /* Get various application definitions. */
- #include "App.protos.h" /* Get the prototypes for application. */
-
- #ifndef __CTLHANDLER__
- #include "CtlHandler.h"
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __DISKINIT__
- #include <DiskInit.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __TEXTEDITCONTROL__
- #include "TextEditControl.h"
- #endif
-
- #ifndef __TEXTSERVICES__
- #include "TextServices.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- extern char gODOCPermission;
- extern Cursor *gCursorPtr;
- extern Boolean gQuitApplication;
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
- #ifdef applec
- #pragma segment DoEvent
- #endif
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Do the right thing for an event. Determine what kind of event it is, and
- ** call the appropriate routines. */
-
- void DoEvent(EventRecord *event)
- {
- Point pt;
- OSErr err;
- WindowPtr rww;
- static Boolean hleQuit = true;
-
- switch(event->what) {
-
- case nullEvent:
- DoIdleTasks(event);
- break;
-
- case mouseDown:
- DoMouseDown(event);
- break;
-
- case autoKey:
- case keyDown: /* Check for menukey equivalents. */
- DoKeyDown(event);
- break;
-
- case activateEvt:
- gCursorPtr = nil; /* Force recalculation of the cursor. */
- DoActivate((WindowPtr)event->message);
- if (TSMTEAvailable()) TSMEvent(event);
- break;
-
- case updateEvt:
- DoUpdate((WindowPtr)event->message);
- break;
-
- /* •••••••• */
- case kHighLevelEvent:
- if (GetNextDocumentWindow(nil, 0)) hleQuit = false; /* If have window, don't auto-force quit. */
- gCursorPtr = nil; /* Force recalculation of the cursor. */
-
- gODOCPermission = fsRdPerm;
- DoHighLevelEvent(event);
- gODOCPermission = fsRdWrPerm;
-
- if (!GetNextDocumentWindow(nil, 0)) hleQuit = false;
- /* If the high-level event was an 'odoc', then it SHOULD have created a document
- ** window. If it didn't, then it wasn't an 'odoc'. If it wasn't an 'odoc', then
- ** we were started up in a normal fashion, so therefore don't force quit. */
- if (GetNextDocumentWindow(nil, 'PtMd')) hleQuit = false;
- /* If a PartMaker document was dropped on us, don't force quit. */
- DoFolders();
- while ((rww = GetNextDocumentWindow(nil, 'rsrc')) != nil) DisposeOneWindow(rww, kClose);
- /* After the DoFolders call, we're done with 'rsrc' documents, so get rid of them. */
- gQuitApplication |= hleQuit;
- break;
- /* The changes above (as compared to AppWannabe code for kHighLevelEvent) is to
- ** handle the various cases of documents being dragged to PartMaker (or not). */
- /* •••••••• */
-
- case osEvt:
- gCursorPtr = nil; /* Force recalculation of the cursor. */
- switch ((event->message >> 24) & 0xFF) {
- /* Must logical and with 0xFF to get only low byte. */
- /* High byte of message. */
-
- case mouseMovedMessage:
- DoIdleTasks(event);
- break;
-
- case suspendResumeMessage:
- /* Suspend/resume is also an activate/deactivate. */
- gInBackground = !((event->message) & resumeFlag);
- CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
- DoActivate(FrontWindow());
- HiliteWindows();
- break;
- }
- break;
-
- case diskEvt:
- gCursorPtr = nil; /* Force recalculation of the cursor. */
- if (HiWord(event->message) != noErr) {
- SetPt(&pt, kDILeft, kDITop);
- err = DIBadMount(pt, event->message);
- }
- break; /* It is not a bad idea to at least call DIBadMount
- ** in response to a diskEvt, so that the user can
- ** format a floppy. */
- }
-
- DoCursor();
- DoAdjustMenus();
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• Called by DTS.Lib..framework. •• */
-
- /* This is called when a window is activated or deactivated. */
-
- void DoActivate(WindowPtr window)
- {
- RgnHandle rgn, oldClip;
- Point pt;
-
- NotifyCancel();
-
- if (IsAppWindow(window)) {
-
- SetPort(window);
- DoCtlActivate(window);
- DoDrawFrame(window, true); /* Redraw frame for new activate state. */
-
- CopyRgn(((WindowPeek)window)->contRgn, rgn = NewRgn());
- DiffRgn(rgn, ((WindowPeek)window)->updateRgn, rgn);
- /* Don't draw any part that's already destined to draw due to an update event.
- ** This prevents part of an exposed window from drawing twice, and thus avoids
- ** flickering. */
-
- BeginContent(window);
-
- pt.h = pt.v = 0;
- GlobalToLocal(&pt);
- OffsetRgn(rgn, pt.h, pt.v);
- /* This offset may seem wrong, since the origin may not be 0,0. It is actually correct,
- ** since at the time of the GlobalToLocal, the port's origin was set to the content origin.
- ** A clearer way to look at this is in two steps:
- ** 1) With the port's origin at 0,0, do a GlobalToLocal on 0,0, and then offset the new clip
- ** by that amount.
- ** 2) Once the port's origin is set correctly, the new clip needs to be offset again, based
- ** on the origin value. (The clipRgn travels with the origin, unlike the visRgn.)
- ** The above is what automatically happens when you do the GlobalToLocal of 0,0 on the
- ** correct origin. Offsets are additive. One step -- no muss, no fuss. */
-
- GetClip(oldClip = NewRgn());
- SetClip(rgn);
- DoDrawControls(window, true); /* Redraw content scrollbars for new activate state. */
- SetClip(oldClip);
- DisposeRgn(oldClip);
- DisposeRgn(rgn);
-
- EndContent(window);
- }
- }
-
-
-
-